#include "WHW_IRQN.h"
#include "All_Init.h"

uint16_t time;
uint8_t flag;
uint8_t can_tx_buffer[8] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x00};
/*定时器捕获中断*/
void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)
{
    if(htim->Instance==TIM5){
        FOC_HALL_CC_IRQ_Handler(&FOC_MOTOR.hall);
    }
}

/*输出捕获中断*/
void HAL_TIM_OC_DelayElapsedCallback(TIM_HandleTypeDef *htim)
{   /*运行周期为2xpwm周期 20khz*/
    if(htim->Instance==TIM1){
        /*速度控制*/
        // FOC_Motor_Speed_Ctrl(&FOC_MOTOR);
    }
}

/*定时器周期中断*/
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
    if(htim->Instance == TIM1){ /*20k Hz*/

        return;
    }

    if(htim->Instance == TIM7){     /*2000Hz的频率 0.5ms计算一次*/
        FOC_Motor_Speed_Calc(&FOC_MOTOR, 0.0005f);
        FOC_Motor_Speed_Ctrl(&FOC_MOTOR);
    }
}

void HAL_ADCEx_InjectedConvCpltCallback(ADC_HandleTypeDef *hadc)
{
    if(hadc->Instance == ADC1)
    {
        FOC_App_Run();                                      /*FOC周期运行*/
    }
}

void HAL_FDCAN_RxFifo0Callback(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo0ITs)
{
	if((RxFifo0ITs & FDCAN_IT_RX_FIFO0_NEW_MESSAGE) != RESET)
	{
		if(hfdcan == &hfdcan1)
		{
			
		}
	}
}

void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
    if(GPIO_Pin == KEY1_Pin)
    {
		
    }

    if(GPIO_Pin == KEY2_Pin)
    {
		
    }

    if(GPIO_Pin == KEY3_Pin)
    {
        
    }

    if(GPIO_Pin == KEY4_Pin)
    {
		
    }
}
